package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.RadioAnchorListData;
import com.rjwh.dingdong.client.util.ViewHolder;
import com.rjwh.dingdong.client.widget.RoundImageView;

/**
 * @author Kay
 * @ClassName RadioAlbumListAdapter
 * @Description
 * @date 2016-10-26
 * @history 2016-10-26 author: description:
 */

public class RadioAnchorListAdapter extends AdapterBase<RadioAnchorListData> {

    private Context mContext;

    public RadioAnchorListAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    protected View getExView(int position, View convertView, ViewGroup parent) throws Exception {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.radio_anchor_list_item, null);
        }

        RoundImageView radioAnchorListItemCoverImg = ViewHolder.get(convertView, R.id.radio_anchor_list_item_cover_img);
        TextView radioAnchorListItemNameTv = ViewHolder.get(convertView, R.id.radio_anchor_list_item_name_tv);
        TextView radioAnchorListItemContentTv = ViewHolder.get(convertView, R.id.radio_anchor_list_item_content_tv);
        TextView radioAnchorListItemSubtitleTv = ViewHolder.get(convertView, R.id.radio_anchor_list_item_subtitle_tv);

        RadioAnchorListData radioAnchorListData = getList().get(position);

        if (radioAnchorListData == null) {
            return convertView;
        }
        String coverurl = radioAnchorListData.getCoverurl();
        String radioname = radioAnchorListData.getRadioname();
        String hotprogram = radioAnchorListData.getHotprogram();
        String album = radioAnchorListData.getAlbum();
        String story = radioAnchorListData.getStory();

        if (!AsStrUtils.isEmpty(radioname)) {
            radioAnchorListItemNameTv.setText(radioname);
        }
        if (!AsStrUtils.isEmpty(hotprogram)) {
            radioAnchorListItemContentTv.setText(hotprogram);
        }
        if (!AsStrUtils.isEmpty(album) && !AsStrUtils.isEmpty(story)) {
            radioAnchorListItemSubtitleTv.setText(album + story);
        }

        Glide.with(mContext).load(coverurl).dontAnimate().placeholder(R.drawable.icon_pic_holder).error(R.drawable.icon_pic_holder)
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(radioAnchorListItemCoverImg);

        return convertView;
    }
}
